package com.manli.api.service;

import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.List;
import com.manli.api.pojo.Result;
import com.manli.api.util.ResultUtil;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import com.manli.api.dao.RolePermissionDao;
import com.manli.api.dto.RolePermission;
import org.springframework.transaction.annotation.Transactional;


@Service("rolePermissionService")
public class RolePermissionService {
    @Autowired
    RolePermissionDao rolePermissionDao;

    
    public Result queryPage(Map<String, Object> params) {
        PageQuery<RolePermission> page = rolePermissionDao.createQuery()
                .page(Long.parseLong(params.get("page").toString()),Long.parseLong(params.get("limit").toString()));
        return ResultUtil.success(page.getList(),page.getTotalRow());
    }

    
    public Result queryAll() {
        List<RolePermission> list = rolePermissionDao.all();
        return ResultUtil.success(list);
    }

    
    public Result getById(Integer roleId) {
        RolePermission rolePermission = rolePermissionDao.single(roleId);
        return ResultUtil.success(rolePermission);
    }

    @Transactional
    public Result save(RolePermission rolePermission) {
        rolePermissionDao.insert(rolePermission);
        return ResultUtil.success();
    }

    @Transactional
    public Result updateById(RolePermission rolePermission) {
        rolePermissionDao.updateTemplateById(rolePermission);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeById(Integer roleId) {
        rolePermissionDao.deleteById(roleId);
        return ResultUtil.success();
    }

    @Transactional
    public Result removeByIds(List<Integer> ids) {
        for (Integer id:ids) {
            rolePermissionDao.deleteById(id);
        }
        return ResultUtil.success();
    }



}
